package top.happylaishop.shop.advice;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.happylaishop.shop.exception.BaseException;
import top.happylaishop.shop.exception.BaseRuntimeException;
import top.happylaishop.shop.utils.resp.BaseResponse;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
public class GlobalExceptionAdvice {


    @ExceptionHandler(value= BaseRuntimeException.class)
    public BaseResponse handleBaseRuntimeException(HttpServletRequest request, HttpServletResponse response, BaseRuntimeException baseException){
        return new BaseResponse(baseException.getStatus(), baseException.getMessage());
    }

    @ExceptionHandler(value= BaseException.class)
    public BaseResponse handleBaseException(HttpServletRequest request, HttpServletResponse response, BaseException baseException){
        return BaseResponse.failed(baseException.getMessage());
    }

}
